import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/route/application.dart';
import 'package:appflutterhomeschool/route/routes.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/notice_tab_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/notice/notice_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

///用户：Nine Tailed Fox
///时间：2020/6/8
///邮箱：1037438704@qq.com
///功能：通知
class NoticePage extends StatefulWidget {
  @override
  _NoticePageState createState() => _NoticePageState();
}

class _NoticePageState extends State<NoticePage>
    with AutomaticKeepAliveClientMixin {

  @override
  // ignore: must_call_super
  Widget build(BuildContext context) {
    return ProviderWidget<NoticeViewModel>(
      model: NoticeViewModel(context),
      onModelReady: (value) {
        value.initView();
        value.initData();
        value.myAppViewModel.noticeViewModel = value;
      },
      builder: (context, viewModel, child) {
        return Scaffold(
          backgroundColor: Colours.gray_f6,
          appBar: MyAppBar(
              finishBool: true,
              imageRightUrl:
                  viewModel.openScreen ? "shaixuan_true" : "shaixuan_false",
              title: viewModel.myAppViewModel.name ?? "未选择",
              onTapLeft: () => Application()
                  .navigatePushToPage(context, Routes.switchClassesPage, {}),
              fontWeight: FontWeight.bold,
              onTapRight: viewModel.onTapOpenScreen),
          body: Column(
            children: <Widget>[
              NoticeTabWidget(
                rightUnread: true,
                //未读还是已读
                unreadBool: viewModel.unreadBool,
                //未读还是已读事件
                unreadBoolOnTap: viewModel.unreadBoolOnTap,
                //是否显示
                openScreen: viewModel.openScreen,
                listTab: viewModel.listTab,
                getIndex: (index) {
                  viewModel.tapModelOnTap(index);
                },
              ),
              Expanded(
                child: SmartRefresher(
                  enablePullDown: true,
                  enablePullUp: true,
                  footer: CustomFotterWidget(),
                  header: ClassicHeader(),
                  controller: viewModel.refreshController,
                  onRefresh: viewModel.onRefresh,
                  onLoading: viewModel.onLoading,
                  child: NoticeListViewWidget(),
                ),
              )
            ],
          ),
          floatingActionButton:
              FloatingButtonWidget(visible: viewModel.myAppViewModel.identity),
        );
      },
    );
  }

  @override
  bool get wantKeepAlive => true;
}
